package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IEntityZoneCategoryDao;
import cn.edu.sjtu.se.dslab.project.EntityZoneCategory;


@Repository("entityZoneCategoryDao")
public class EntityZoneCategoryDaoImpl implements IEntityZoneCategoryDao {

	@Resource(name = "baseDao")
	private IBaseDao<EntityZoneCategory> baseDao;
	
	@Override
	public EntityZoneCategory queryById(long id) {
		return baseDao.queryById(EntityZoneCategory.class, id);
	}

	@Override
	public EntityZoneCategory queryByName(String name) {
		StringBuffer hql = new StringBuffer();
		hql.append("from EntityZoneCategory where name=");
		hql.append("'" + name + "'");
		return baseDao.queryObject(hql.toString());
	}

	@Override
	public List<EntityZoneCategory> queryByList() {
		return baseDao.queryList(EntityZoneCategory.class.getName());
	}

	@Override
	public void save(EntityZoneCategory entityZoneCategory) {
		baseDao.save(entityZoneCategory);
	}

	@Override
	public EntityZoneCategory update(EntityZoneCategory entityZoneCategory) {
		return baseDao.update(entityZoneCategory);
	}

	@Override
	public void deleteEntityZoneCategory(EntityZoneCategory entityZoneCategory) {
		baseDao.delete(entityZoneCategory);
	}

	@Override
	public List<EntityZoneCategory> queryByProject(long projectId) {
		StringBuilder sql = new StringBuilder();
		sql.append("from EntityZoneCategory where project_id='");
		sql.append(projectId).append("'");
		return baseDao.query(sql.toString());
	}

	@Override
	public EntityZoneCategory queryByProjectAndName(long projectId, String name) {
		StringBuilder sql = new StringBuilder();
		sql.append("from EntityZoneCategory where project_id='");
		sql.append(projectId).append("' and name = '").append(name).append("'");
		return baseDao.queryObject(sql.toString());
	}

}
